package bite20220320;

public class FibTest {
    public static int fib(int n){
        if (n==0){
            return 1;
        }
        if (n==1){
            return 1;
        }
        return fib(n-1)+fib(n-2);//会有大量的重复计算
    }
    public static int fib_(int n){
        int fib0 = 0;
        int fib1 = 1;
        int fib2 = 0;
        for (int i = 0; i < n - 1; i++) {
            fib2 = fib0 + fib1;
            fib0 = fib1;
            fib1 = fib2;
        }
        return fib2;
    }
    public static void main(String[] args){
        System.out.println(fib_(1));
        System.out.println(fib_(2));
        System.out.println(fib_(3));
        System.out.println(fib_(4));
        System.out.println(fib_(7));

    }
}
